import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import Components from 'unplugin-vue-components/vite';
import AutoImport from 'unplugin-auto-import/vite';
import { VantResolver } from 'unplugin-vue-components/resolvers';
import { fileURLToPath, URL } from 'node:url';
import vuetify from 'vite-plugin-vuetify';
import ViteSvgPlugin from 'vite-plugin-svg';

// https://vitejs.dev/config/
export default defineConfig({
  base: './',
  mode: '',
  server: {
    open: true,
    proxy: {
      '/api': {
        target: 'http://localhost:8080',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '')
      }
    }
  },
  plugins: [
    ViteSvgPlugin(),
    vue(),
    vuetify({ autoImport: true }),
    Components({
      resolvers: [VantResolver()]
    }),
    AutoImport({
      include: [
        /\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
        /\.vue$/,
        /\.vue\?vue/, // .vue
        /\.md$/ // .md
      ],
      globs: ['src/components/*.{vue}'],
      imports: ['vue', 'vue-router'],
      dts: false,
      eslintrc: {
        enabled: false
      }
    })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  build: {
    chunkSizeWarningLimit: 500,
    rollupOptions: {
      output: {
        manualChunks(id) {
          if (id.includes('node_modules')) {
            return 'vendor';
          }
        }
      },
      // external: [
      //   'src/assets/tb166.svg',
      //   'src/assets/tb97.svg',
      //   'src/assets/tb138.svg',
      //   'src/assets/tb139.svg',
      //   'src/assets/tb110.svg',
      //   'src/assets/tb104.svg',
      //   'src/assets/tb144.svg',
      //   'src/assets/tb309.svg'
      // ]
    }
  }
});
